#ifndef FAULTINFODIALOG_H
#define FAULTINFODIALOG_H

#include <QDialog>
#include <QSqlTableModel>
#include <QTextCodec>
#include <QModelIndex>
#include <QStandardItemModel>
#include <QTableWidget>
#include "ifuncwin.h"
#include "reagentinfodialog.h"
#include "progessdialog.h"
#include "operatemanage.h"
#include "logindialog.h"

namespace Ui {
class FaultInfoDialog;
}
//class ReagentInfoDialog;
class FaultInfoDialog : public QDialog,public OperateManage
{
    Q_OBJECT

public:
    explicit FaultInfoDialog(QWidget *parent = 0);
    ~FaultInfoDialog();

    void showEvent(QShowEvent *e);
    void closeEvent(QCloseEvent *e);
    void tableWidget_creat();
    void seccssdeal_fault();
    void clearFault_step();
    void clearFault_step_familytwo();
    void clearFault_step_familythree();
    void clearFault_step_familyfour();
    void changreaget_dialogshow(char checkStatus);
    void Faultto_clearFault();
    void Faultsccussdeal_save_journal(int dealsccussNum);
    bool FaultOperateManage();
    int breplaceReagent(int ReagentName);
    bool  hardware_V_check(int vcheckflg );
    bool wintoclearfault(int faultnum);

private slots:
    void on_Btn_clearFault_clicked();
    void on_Btn_faultDelete_clicked();
    void on_Btn_faultInfoClose_clicked();
    void on_Btn_down_clicked();
    void on_Btn_up_clicked();
    void updatefaultInfo();
    void faultInfo_pressedHandle(int, int);
    void Faultdealsyms();
    void on_Btn_faultDelete_2_clicked();
    bool reagentcolseflg(bool flg);//bool flg
    bool otherreagentdealflg(int reagentnum);
    bool otherclearfault(int faultnum);
signals:
    void sendFaultInfoClear(int, bool);
    void sendreadreadmicroswitch(QString type);
    void sendbuttonclick(QString id,QString sampleNum);
    void sendreagetsamNum(QString sampleNum);
    void sendfaultcode(QString code,QStringList list);
    void sendtimeerrtorg();
    bool sendshowdialog(QString,QString);
protected slots:
    void UpdateProgess();
    void progressBarinit(int times);
    void progressBarstop();
    void receivetimessuccessignals(int,bool,bool);
    void receivesuccessignals(int,bool);
    void receiveallsignals(QString id, QStringList list);
    void Showfaultdialog();
    void ifuncreadmicroswitch();
private:
    Ui::FaultInfoDialog *ui;
    QSqlTableModel *model;
    QTextCodec *tc;
    QByteArray ba;
    ReagentInfoDialog *reagentInfodialog;
    SerialPort *serialport;
    LogInDialog *logindialog;
    bool reagentdialogwinshowflg ;
    float adjustVal[1];
    float pressure[1];

    int faultNum;
    QStringList faultCode;
    QStringList faultState;
    QStringList faultDescrip;
    QStringList faultdealorder;
    int listingrow;
    int selectedIndex;
    QTimer *timer;
    QTimer *timerreadmicroswitch;
    QTimer *timermicroswitchdeal;
    int num;
    int posnum;
    void set_btn_state();
    int get_faultInfo_from_db();
    void fill_tableWidget_faultInfo();

    bool Xsamexeflg;
    bool Ysamexeflg;
    bool Diffexeflg;
    bool Dilexeflg;
    bool communcheckflg ;

    volatile bool Xsamreturnflg;
    volatile bool Ysamreturnflg;
    volatile bool Diffreturnflg;
    volatile bool Dilreturnflg;
    volatile bool Dilreagentreturnflg;
    volatile bool Lhreagentreturnflg;
    volatile bool Diffreagentreturnflg;
    volatile bool fluidreturnflg;
    bool oldfaultallowEnterSleep;
    bool oldfaultallowMaintenanceExe;

    bool Btclearfaultflg ;//TRUE 消除故障按钮动作正在执行标志
    int Btclearfaultstep ;

    int Communcheckrepeat ;
    int XsamErrrepeat ;
    int YsamErrrepeat;
    int DiffErrrepeat;
    int DilErrrepeat;

    int Dilreagentrepeat;
    int Lhreagentrepeat;
    int Diffreagentrepeat;

    int negativeErrrepeat;
    int hydraulicpressurerepeat;
    int fluidErrrepeat;

    int Diltempalarmrepeat;
    int Difftempalarmrepeat;

    int Hgbalarmrepeat;
    int Vhalarmrepeat;

    int reset_exeoverflg;//电机自检后已经执行一次复位 兼容性强
    QString  FalutSummaInfo;
    QString  FalutinfoFunc;
    bool isOpenResagent;//true close  false open
    KMessageBox msgBox;

};

#endif // FAULTINFODIALOG_H
